In [18]:
limit = 1000
m3 = [3 * i for i in range(limit/3 + 1) if i > 0 and 3 * i < limit]
Another list with the multipliers of 5 below 5
In [19]:
m5 = [5 * i for i in range(limit/5 + 1) if i > 0 and 5 * i < limit]
The two list are joint and converted into a set so to avoid repeated numbers (for example, 15 es a multiplier of 3 and 5)
In [20]:
l = set(m3 + m5)
Sum all the elements
In [21]:
sum = 0
for e in l:
sum += e
Print the solution to the problem
In [29]:
print("The solution to the problem is {}").format(sum)
In [28]: